#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <unistd.h>


int main()
{

	key_t key;
	int shmid;
	char* buf;

	key = ftok("test", 100);
	if(key < 0)
	{
		perror("ftok");
	}
	printf("key = %d", key);

	//打开共享内存
	shmid = shmget(key, 64, IPC_CREAT|0666);
	if(shmid < 0)
	{
		perror("shmget");
	}

	//内存映射
	buf = shmat(24,NULL, 0);
	if(buf < 0)
	{
		perror("shmat");
	}

	printf("read = %s\n",buf);

	shmdt(buf);
	shmctl(shmid, IPC_RMID, NULL);


}















